﻿<%@ WebHandler Language="C#" Class="YPTitaniumMaterialHandler" %>

using System;
using System.Web;
using System.Collections.Generic;
using System.Web.Script.Serialization;
using System.Linq;
using BusinessRule.Business;
using System.Data;
using Newtonsoft.Json;
using System.IO;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using NPOI.HSSF.UserModel;
using System.Collections;
using BusinessRule.DTO;
using System.Web.SessionState;

//Description: 叶片钛合金处理程序
//Copyright (c) : 通力凯顿（北京）系统集成有限公司
//Writer:zhangrj
//create Date:2022-01-12
public class YPTitaniumMaterialHandler : IHttpHandler, IRequiresSessionState
{
    YPContainerBusiness ypContainerBusiness = new YPContainerBusiness();
    public void ProcessRequest(HttpContext context)
    {
        try
        {
            var action = context.Request.Form["action"].ToString();
            switch (action)
            {
                case "GetPageList":
                    GetPageList(context);
                    break;
                case "Save":
                    SaveData(context);
                    break;
                default:
                    break;
            }
        }
        catch (Exception e)
        {
            context.Response.Write(JsonConvert.SerializeObject(new uMESProcessResult() { Message = "出错了：" + e.Message, Result = false }));
        }
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

    /// <summary>
    /// 查询获取列表
    /// </summary>
    /// <param name="context"></param>
    public void GetPageList(HttpContext context)
    {
        Dictionary<string, string> para = new Dictionary<string, string>();
        para.Add("pageNumber", context.Request.Form["pageNumber"].ToString());//页码
        para.Add("pageSize", context.Request.Form["pageSize"].ToString());//每页页数
        if (!string.IsNullOrWhiteSpace(context.Request.Form["materialtrademark"]))
        {
            para.Add("Materialtrademark", context.Request["materialtrademark"].ToString());
        }
        para.Add("IsTitanium", context.Request["isTitanium"].ToString());
        uMESProcessResult result = ypContainerBusiness.GetTitaniumInfoForPage(para);
        context.Response.Write(JsonConvert.SerializeObject(result));
    }

    /// <summary>
    /// 保存勾选的数据
    /// </summary>
    /// <param name="context"></param>
    public void SaveData(HttpContext context)
    {
        CurrentUserInfo m_UserInfo = (CurrentUserInfo)context.Session["CurrentUserInfo"];
        string titanium = context.Request.Form["titanium"].ToString();//钛合金状态
        DataTable dt = JsonConvert.DeserializeObject<DataTable>(context.Request.Form["tableData"].ToString());
        if (dt.Rows.Count==0)
        {
            context.Response.Write(JsonConvert.SerializeObject(new uMESProcessResult() { Message = "未选择数据", Result = false }));
            return;
        }
        Dictionary<string, string> dic = new Dictionary<string, string>();
        dic.Add("titanium", titanium);
        dic.Add("CreateEmployeeId", m_UserInfo.EmployeeID.ToString());
        uMESProcessResult result = ypContainerBusiness.SaveTitaniumData(dt, dic);
        context.Response.Write(JsonConvert.SerializeObject(result));
    }
}